package fr.afcepf.vod.managedbean;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import fr.afcepf.vod.entities.Client;
import fr.afcepf.vod.metier.IGestionConnexion;

@ManagedBean
@SessionScoped
public class MbConnexion {

	@ManagedProperty(value = "#{gestionConnexionImpl}")
	private IGestionConnexion gestionConnexionImpl; // +get/set


	private String email;
	private String password;
	private String label;
	private Client client;

	public String connexion() {

		String page = "";

		if (gestionConnexionImpl.connexionAutorisee(email, password)) {
			int idTypeAcces = gestionConnexionImpl.recupIdDroitAcces(email,
					password);
			switch (idTypeAcces) {
			case 1:
				page = "AccueilClient.jsf";
				client = gestionConnexionImpl.recupClient(email, password);
				break;
			case 2:

				page = "AccueilAdmin.jsf";
				break;
			case 3:

				page = "AccueilTech.jsf";
				break;

			default:
				page = "";
				break;
			}
		}
		email = "";
		password = "";

		return page;
	}
	
	public String deconnexion(){
		FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
		return "AccueilVisiteur.jsf";
	}
	
	// if (){
	// label="Votre et/ou votre mot de passe est incorrect";
	// }

	public IGestionConnexion getGestionConnexionImpl() {
		return gestionConnexionImpl;
	}

	public void setGestionConnexionImpl(IGestionConnexion gestionConnexionImpl) {
		this.gestionConnexionImpl = gestionConnexionImpl;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}

}
